cmake_minimum_required(VERSION 3.8)
project(pointcloud)

# [FIX] 添加此行以消除CMP0074警告
cmake_policy(SET CMP0074 NEW)

# --- 1. 全局设置 ---
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# --- 2. 查找依赖项 ---
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)

# --- 3. 定义可执行文件和它们的依赖 ---

set(ROS_DEPS
  rclcpp
  sensor_msgs
  pcl_conversions
)

# === 目标: pointcloud2_to_pcd ===
add_executable(pointcloud2_to_pcd src/pointcloud2_to_pcd.cpp)
ament_target_dependencies(pointcloud2_to_pcd ${ROS_DEPS})
target_include_directories(pointcloud2_to_pcd PUBLIC ${PCL_INCLUDE_DIRS})
# [FIX] 使用普通签名，移除PRIVATE关键字以匹配ament的风格
target_link_libraries(pointcloud2_to_pcd ${PCL_LIBRARIES})

# === 目标: pcd_intensity_filter ===
add_executable(pcd_intensity_filter src/pcd_intensity_filter.cpp)
ament_target_dependencies(pcd_intensity_filter ${ROS_DEPS})
target_include_directories(pcd_intensity_filter PUBLIC ${PCL_INCLUDE_DIRS})
# [FIX] 使用普通签名，移除PRIVATE关键字
target_link_libraries(pcd_intensity_filter ${PCL_LIBRARIES})

# === 目标: pointcloud_pub ===
add_executable(pointcloud_pub src/pointcloud_pub.cpp)
ament_target_dependencies(pointcloud_pub ${ROS_DEPS})
target_include_directories(pointcloud_pub PUBLIC ${PCL_INCLUDE_DIRS})
# [FIX] 使用普通签名，移除PRIVATE关键字
target_link_libraries(pointcloud_pub ${PCL_LIBRARIES})

# --- 4. 安装目标 ---
install(TARGETS
  pointcloud2_to_pcd
  pcd_intensity_filter
  pointcloud_pub
  DESTINATION lib/${PROJECT_NAME}
)

# --- 5. ament Lint和Package定义 ---
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()